package com.ep.stepview;

import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.animation.DecelerateInterpolator;

import com.ep.stepview.view.CircleProgressBar;
import com.ep.stepview.view.ColorTrackTextView;
import com.ep.stepview.view.StepView;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";
    private StepView mStepView;
    private CircleProgressBar mCircleProgressBar;
    private ColorTrackTextView mColorTrackTextView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mCircleProgressBar= (CircleProgressBar) findViewById(R.id.circleProgressBar);
        mStepView = (StepView) findViewById(R.id.stepView);
        mColorTrackTextView= (ColorTrackTextView) findViewById(R.id.textView);

        mStepView.setMaxStep(4000);
        ValueAnimator valueAnimator = ObjectAnimator.ofFloat(0, 3000);
        valueAnimator.setDuration(3000);
        valueAnimator.setInterpolator(new DecelerateInterpolator());
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float curStep = (float) animation.getAnimatedValue();
                mStepView.setCurStep((int) curStep);

            }
        });
        valueAnimator.start();


        ValueAnimator valueAnimator2= ObjectAnimator.ofFloat(0,100);
        valueAnimator2.setDuration(3000);
        valueAnimator2.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float curProgress= (float) animation.getAnimatedValue();
                mCircleProgressBar.setCurProgress(curProgress);
            }
        });
        valueAnimator2.start();
    }


    public void leftToRight(View view){
        mColorTrackTextView.setDirection(ColorTrackTextView.Direction.LEFT_TO_RIGHT);

        ValueAnimator valueAnimator= ObjectAnimator.ofFloat(0,1);
        valueAnimator.setDuration(3000);
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float curProgress= (float) animation.getAnimatedValue();
                mColorTrackTextView.setCurProgress(curProgress);
            }
        });
        valueAnimator.start();
    }
    public void rightToLeft(View view){
        mColorTrackTextView.setDirection(ColorTrackTextView.Direction.RIGHT_TO_LEFT);

        ValueAnimator valueAnimator= ObjectAnimator.ofFloat(0,1);
        valueAnimator.setDuration(3000);
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float curProgress= (float) animation.getAnimatedValue();
                mColorTrackTextView.setCurProgress(curProgress);
            }
        });
        valueAnimator.start();
    }
}
